package pearson.automation.forms;

import org.openqa.selenium.By;

import framework.BaseForm;
import framework.elements.Button;
import framework.elements.Label;

public class AssetDetailsPopupForm extends BaseForm {
    
    private static Label title =
        new Label(By.xpath("//div[@class='item-info']/hgroup/h1"), "Title");
    private Button close =
        new Button(By.linkText("Close"), "Close");
    private Label type =
        new Label(By.id("detailed-results"), "Element Type");
    private Label thumbnail =
        new Label(By.xpath("//div[@class='item-image']//img"), "Thumbnail");
    
    private Button preview =
        new Button(By.className("preview-cta"), "Preview button");
    private Button newButton =
        new Button(By.className("cta-new"), "New button");
    private Button flowPlayer =
        new Button(By.tagName("iframe"), "Flow player");
    
    protected AssetDetailsPopupForm() {
        super(title.getLocator(), "Details Popup");
    }

    public void clickClose() {
        close.clickAndWait();
        title.waitForElementDissapear();
    }
    
    public LightBoxForm clickPreview() {
        preview.clickAndWait();
        return new LightBoxForm();
    }
    
    public LightBoxForm clickThumbnail() {
        thumbnail.clickAndWait();
        return new LightBoxForm();
    }
    
    public String getAssetType() {
        return type.getElement().getAttribute("data-content-type");
    }

    public String getAssetTitle() {
        return title.getText();
    }
    
    public boolean hasPreviewButton() {
        return preview.isPresent(5);
    }
    
    public boolean hasNewButton() {
        return newButton.isPresent(5);
    }
    
    public boolean hasFlowplayer() {
        return flowPlayer.isPresent(5);
    }
    
}
